package com.chencs.lm.controller;

import com.chencs.lm.service.LmWebMemberSer;
import com.chencs.lm.service.LmWebProductSer;
import com.chencs.utils.JumpUtils;
import com.chencs.utils.SessionUtils;
import com.chencs.vo.biz.lianmeng.LmUser;
import framework.model.ResponseOptUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
@RestController
@RequestMapping("/web/product")
public class LmWebProductCtr  {

    private static final Logger logger = LoggerFactory.getLogger(LmWebProductCtr.class);

    @Autowired
    private LmWebProductSer productSer;
    /**
     *
     * @param session
     * @return
     */
    @RequestMapping(value = "/listPage", method = RequestMethod.GET)
    public ModelAndView listPage(HttpSession session) {
        ModelAndView modelAndView = new ModelAndView();
        LmUser user = SessionUtils.getUser(session);
        if(user==null){
            return JumpUtils.jumpLogin();
        }else{
            modelAndView.setViewName("lm/biz/product/product_list");
        }
        return modelAndView;
    }


    @RequestMapping(value = "/product_list", method = RequestMethod.GET)
    public String product_list() {
        String retStr = "";
        try {
            retStr = productSer.getList();
        } catch (Exception e) {
            retStr = ResponseOptUtil.commonMsgError( ResponseOptUtil.RET_FAIL_MSG);
            e.printStackTrace();
        }
        logger.info("product_list param: {}", retStr);
        return retStr;
    }




    /**
     *
     * @param session
     * @return
     */
    @RequestMapping(value = "/categoryListPage", method = RequestMethod.GET)
    public ModelAndView categoryListPage(HttpSession session) {
        ModelAndView modelAndView = new ModelAndView();
        LmUser user = SessionUtils.getUser(session);
        if(user==null){
            return JumpUtils.jumpLogin();
        }else{
            modelAndView.setViewName("lm/biz/category/category_list");
        }
        return modelAndView;
    }




    /**
     *
     * @return
     */
    @RequestMapping(value = "/lmCategoryList", method = RequestMethod.GET)
    public String lmCategoryList() {
        String retStr = "";
        try {
            retStr = productSer.getLmCategoryList();
        } catch (Exception e) {
            retStr = ResponseOptUtil.commonMsgError( ResponseOptUtil.RET_FAIL_MSG);
            e.printStackTrace();
        }
        logger.info("product_list param: {}", retStr);
        return retStr;
    }



    /**
     *
     * @param session
     * @return
     */
    @RequestMapping(value = "/categoryItemListPage", method = RequestMethod.GET)
    public ModelAndView categoryItemListPage(HttpSession session) {
        ModelAndView modelAndView = new ModelAndView();
        LmUser user = SessionUtils.getUser(session);
        if(user==null){
            return JumpUtils.jumpLogin();
        }else{
            modelAndView.setViewName("lm/biz/category/categoryItem_list");
        }
        return modelAndView;
    }



    /**
     *
     * @return
     */
    @RequestMapping(value = "/getLmCategoryItem", method = RequestMethod.GET)
    public String getLmCategoryItem(@RequestBody String cid) {
        String retStr = "";
        try {
            retStr = productSer.getLmCategoryItem(cid);
        } catch (Exception e) {
            retStr = ResponseOptUtil.commonMsgError( ResponseOptUtil.RET_FAIL_MSG);
            e.printStackTrace();
        }
        logger.info("product_list param: {}", retStr);
        return retStr;
    }



}
